import threading
from threading import Thread,Lock
import time
ticket=50#假设为50张票
lock_obj=Lock()#创建锁对象
def ticket_sell():
    global ticket

    #每个排队窗口假设有100人
    for i in range(0,100):#每个线程要执行100次循环
        lock_obj.acquire()
        if ticket<0:
            pass
        elif ticket>=0:
            print(f'执行线程：{threading.current_thread().name},当前还剩余{ticket}张票')
            ticket -= 1
            #time.sleep()
        lock_obj.release()
if __name__=='__main__':
    for item in range(3):#创建三个线程，代表三个窗口
        p=Thread(target=ticket_sell)
        p.start()#启动了线程
